<template>
    <view class="scrollbox">
        <u-navbar title="补录合同">
            <template #right>
                <!--  -->
                <view class="edtbtn" @click="onedt"> 添加 </view>
            </template>
        </u-navbar>
        <getdatascrollview ref="getdatascrollview" :api="api" :seardata="tablequery">
            <template #default="{ list }">
                <view class="searchcontent">
                    <selectzitem v-model="searchdata.projectCode" style="flex: 1;" :options="projectCodes"
                        @change="change" :btnfalg="true">
                    </selectzitem>
                    <view class="sx" @click="sxfn">
                        筛选<u-icon name="arrow-down"></u-icon>
                    </view>
                </view>
                <listcard v-for="item in list" :item="item" :list="listinputs" @click="onedt(item)">
                    <!-- <template #after>
                        <view class="u-flex u-flex-end" style="padding-right: 20rpx">
                            <u-tag text="修改" @click="onedt(item)"></u-tag>
                            <view style="width: 20rpx;"></view>
                            <u-tag text="审核" @click="(item)"></u-tag>
                            <view style="width: 20rpx;"></view>
                            <u-tag text="删除" type="error" @click="ondel(item)"></u-tag>
                        </view>
                    </template> -->
                </listcard>
            </template>
        </getdatascrollview>
        <sxpopup ref="sxpopup" :searchdata="searchdata"></sxpopup>
    </view>
</template>

<script>
import { getTypeList } from "@/api/projectManage/projectType";
import {
    requestList,

} from "@/api/contract/contractEntry";
export default {
    components: {},
    data() {
        return {
            projectCodes: [],
            customstyle: {
                margin: 0,
                flex: 0,
            },
            tablequery: {
                contractSource: "ENTRY"
            },
            api: requestList,
            searchdata: {
                contractSource: "ENTRY"
            },
            searchinputs: [
                {
                    label: "合同编号",
                    value: "contractCode",
                },
                {
                    label: "合同名称",
                    value: "contractName",
                },
                {
                    label: "合同类型",
                    value: "contractType",
                    type: "select",
                    option: this.$store.state.dict.dictDatas[
                        "contract_type"
                    ],
                },
                {
                    label: "客户单位",
                    value: "customerName",
                },
                {
                    label: "开始日期",
                    value: "applicationTimeStart",
                    type: "datetime",

                },
                {
                    label: "结束日期",
                    value: "applicationTimeEnd",
                    type: "datetime",

                },

            ],
            listinputs: [{
                "label": "合同编号",
                "value": "contractCode"
            },
            {
                "label": "合同名称",
                "value": "contractName"
            },
            {
                "label": "合同类型",
                "value": "contractType",
                "type": "select",
                "option": this.$store.state.dict.dictDatas[
                    "contract_type"
                ],
            },
            {
                "label": "合同状态",
                "value": "contractStatus",
                "type": "select",
                "option": this.$store.state.dict.dictDatas[
                    "contract_status"
                ],
            },
            {
                "label": "所属项目编号",
                "value": "projectCode"
            },
            {
                "label": "所属项目名称",
                "value": "projectName"
            },
            {
                "label": "客户单位名称",
                "value": "customerName"
            },
            {
                "label": "合同签订日期",
                "value": "signingDate"
            },
            {
                "label": "合同有效履行日期始",
                "value": "performanceDateStart"
            },
            {
                "label": "合同有效履行日期止",
                "value": "performanceDateEnd"
            },
            {
                "label": "合同金额",
                "value": "amount"
            },
            {
                "label": "需要回款",
                "value": "returned",
                "type": "select",
                "option": this.$store.state.dict.dictDatas[
                    "is_yes_no"
                ]
            },
            {
                "label": "合同负责人",
                "value": "contractManager"
            },
            {
                "label": "合同联系人",
                "value": "contractContact"
            },
            {
                "label": "合同申请人",
                "value": "contractApplicantName"
            },
            {
                "label": "合同申请时间",
                "value": "contractApplicationTime",
                type: "date"
            },

            ]
        };
    },
    onLoad() {
        // console.log(this.$store.state.dict.dictDatas[
        //     "contract_status"
        // ], 261);
        this.init();
    },
    onShow() {
        this.$refs.getdatascrollview && this.$refs.getdatascrollview.onRefresh();
    },
    methods: {
        async init() {
            getTypeList().then((e) => {
                this.projectCodes = e.data.map((item) => {
                    return {
                        label: item.typeName,
                        value: item.typeCode,
                    };
                });
            });
        },
        change() {
            console.log("this.tablequery");
            this.onsearch();
        },
        sxfn() {
            this.$refs.sxpopup.open(this.searchinputs).then((data) => {
                this.searchdata = {
                    ...this.searchdata,
                    ...data,
                };
                this.onsearch();
            });
        },
        async onsearch() {
            this.tablequery = {
                ...this.searchdata,
            };

            this.$nextTick(() => {
                this.$refs.getdatascrollview.onRefresh();
            });
        },
        ondel(row) {
            console.log(row);
            uni.showModal({
                title: "提示",
                content: "是否删除此数据？",
                success: (res) => {
                    if (res.confirm) {
                        deleteCompanyFile([row.uuid]).then((e) => {
                            this.onsearch();
                        });
                    } else if (res.cancel) {
                        console.log("用户点击取消");
                    }
                },
            });
        },
        onedt(item) {
            if (item.uuid) {
                uni.navigateTo({
                    url: `/pageswork/contract/supplementary/edit?id=${item.uuid}`,
                });
            } else {
                uni.navigateTo({
                    url: "/pageswork/contract/supplementary/edit",
                });
            }

        },

    },
};
</script>
<style>
page {
    background: #fff;
}
</style>
<style lang="scss" scoped>
.edtbtn {
    color: #1890ff;
    font-size: 28rpx;
}

.searchcontent {
    display: flex;
    align-items: center;
    padding: 20rpx 20rpx 0 20rpx;

    .sx {
        padding-left: 20rpx;
        display: flex;
        font-size: 28rpx;
    }
}
</style>
